<template>
  <div>
    <c-table-box
      ref="cTableBox"
      hide-func
      checkbox
      :off-set="-20"
      :other-filters="otherFilters"
      :table-config="tableConfig"
      @selection-change="selectionChange"
    >
      <template #btn>
        <c-permission v-if="type==='all'" code="all">
          <c-button opt-code="add" size="mini" type="primary" @click="add">门头新增</c-button>
          <c-button opt-code="export" size="mini" type="primary" @click="handleExport">导出</c-button>
          <c-button opt-code="seriesExport" size="mini" type="primary" @click="handleExport(true)">系列导出</c-button>
          <c-button opt-code="submitChange" size="mini" type="primary" @click="handleChange">发起变更</c-button>
          <c-button opt-code="designChange" size="mini" type="primary" @click="handleDesignChange">设计变更</c-button>
          <c-button opt-code="pause" size="mini" type="primary" @click="pause">暂停</c-button>
          <c-button opt-code="renew" size="mini" type="primary" @click="regain">恢复</c-button>
          <c-button opt-code="changeLevel" type="primary" @click="changeLevel">变更等级</c-button>
          <c-button opt-code="customizedExport" type="primary" @click="handleExport('customized')">定制报图导出</c-button>
        </c-permission>
        <c-permission v-else-if="type==='submit'" code="submit">
          <c-button opt-code="edit" size="mini" type="primary" @click="edit">编辑</c-button>
          <c-button opt-code="AppDelay" size="mini" type="primary" @click="extensionRequest">延期申请</c-button>
          <c-button opt-code="subtermination" size="mini" type="primary" @click="handleTerminal">终止 </c-button>
          <c-button opt-code="export" size="mini" type="primary" @click="handleExport">导出</c-button>
        </c-permission>
        <c-permission v-else-if="type==='confirm'" code="confirm">
          <c-button opt-code="confirm" size="mini" type="primary" @click="handleConfirm">设计申请确认</c-button>
          <c-button opt-code="export" size="mini" type="primary" @click="handleExport">导出</c-button>
        </c-permission>
      </template>
    </c-table-box>
    <el-dialog
      :visible.sync="delayVisible"
      width="70%"
      :close-on-click-modal="false"
      title="设计申请延期"
    >
      <el-form
        ref="refDelayForm"
        title="设计申请延期"
        :model="delayForm"
        :rules="ruleDelayForm"
        label-width="90px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="门店:" prop="shopName">
              {{ current.shopName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户:">
              {{ current.clientName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="装修项目号:">
              {{ current.constCode }}
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="延期说明:" prop="exceptionDesc">
              <el-input
                v-model="delayForm.exceptionDesc"
                type="textarea"
                maxlength="1000"
                show-word-limit
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="原计划提报设计申请时间:">
              {{ current.expectReportApplyTime }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="延期后预计提报时间:" prop="afterAdjustTime">
              <el-date-picker
                v-model="delayForm.afterAdjustTime"
                type="date"
                :clearable="false"
                :picker-options="pickerOptions"
                placeholder="选择日期"
                value-format="yyyy-MM-dd 23:59:59"
                @change="changeDate"
              />
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="延期天数:">
              {{ delayForm.delayDay }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请人:">
              {{ this.$store.getters.user.data.userName }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请时间:">
              {{ nowTime() }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="附件上传">
                <c-file-table-box v-model="files" type-code="ACCESS142" :table-height="60" belong-model="SHOP_DESIGN" :model-id="current.id" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>

      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="closeDelayForm">取 消</el-button>
        <el-button size="mini" :loading="delayLoading" type="primary" @click="submitdelayForm()">确 定</el-button>
      </span>
    </el-dialog>
    <confirm-dlg v-if="confirmVisible" ref="refConfirmDlg" :visible.sync="confirmVisible" :current="current" @on-success="refreshTableData" />
    <stop-design v-if="pauseVisible" ref="refDlg" :visible.sync="pauseVisible" :current="current" @on-success="refreshTableData" />
    <export-files v-if="exportVisible" :title="isCustomize?'定制产品报图系列导出':'导出'" :config="exportAllConfig" :visible.sync="exportVisible" @success="handleExportSuccess" />
    <!-- 终止 -->
    <template>
      <!-- outerVisible = true -->
      <el-dialog title="终止" :visible.sync="outerVisible">
        <el-dialog
          width="30%"
          title="提示"
          :visible.sync="innerVisible"
          append-to-body
        />
        <el-form
          ref="refTerminalForm"
          title="终止"
          :model="terminationForm"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item :rules="[{required:true,message:'请输入终止原因'}]" label="终止原因:" prop="endReason">
                <el-input v-model="terminationForm.endReason" show-word-limit maxlength="1000" type="textarea" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="outerVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleConfirmTerminal">确定</el-button>
        </div>
      </el-dialog>
    </template>
    <!-- 门店等级变更 -->
    <el-dialog
      title="等级/紧急程度修改"
      :visible.sync="showDlg"
      width="25%"
      :before-close="handleClose"
    >
      <el-form
        label-width="80px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="门店等级">
              <el-select v-model="levelValue" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in levelValueOptions"
                  :key="item.dictCode"
                  :label="item.dictName"
                  :value="item.dictCode"
                />
              </el-select></el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="紧急程度">
              <el-select v-model="picUrgentLevel" style="width:100%" placeholder="请选择">
                <el-option
                  v-for="item in picUrgentOptions"
                  :key="item.dictCode"
                  :label="item.dictName"
                  :value="item.dictCode"
                />
              </el-select></el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <!-- </el-select>
           <el-select v-model="levelValue" style="width:100%" placeholder="请选择">
        <el-option
          v-for="item in levelValueOptions"
          :key="item.dictCode"
          :label="item.dictName"
          :value="item.dictCode"
        />
      </el-select> -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="showDlg = false">取 消</el-button>
        <el-button type="primary" @click="handleSureLevel">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 定制报图导出 -->
    <el-dialog
      title="定制产品报图系列导出"
      :visible.sync="showCustomizeDlg"
      width="500px"
    >
      <el-form
        label-width="80px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="范围:">  选中的数据行   </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="文件名:">
              <el-input v-model="fileName" size="mini" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showCustomizeDlg = false">取 消</el-button>
        <el-button type="primary" @click="handleCustomize">导 出</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { termination, editShopLevelCode, getCustomizeFile } from '@/api/shopDesign'
import ConfirmDlg from './confirmDlg.vue'
import { getDictByPatchType } from '@/api/dataDict'
import { getExceptionType, saveException, getAreaList } from '@/api/common'
import stopDesign from './stopDlg.vue'
import { nowTime } from '@/utils/tool'
import { otherFiltersItem } from '@/utils'
export default {
  name: 'List',
  components: {
    stopDesign,
    ConfirmDlg
  },
  props: {
    type: {
      type: String,
      default: ''
    },
    activeType: {
      type: String,
      default: ''
    },
    serachFilters: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      flag: false,
      showCustomizeDlg: false, // 定制报图导出
      showDlg: false,
      isCustomize: false,
      files: [],
      fileName: '定制产品报图系列',
      outerVisible: false,
      innerVisible: false,
      exportVisible: false,
      typeFilters: [],
      id: '',
      nowTime,
      delayLoading: false,
      stopLoading: false,
      terminationForm: {
        id: '',
        endReason: ''
      },
      doorHeadOptions: [],
      constTypeOptions: [],
      decorationRangeOptions: [],
      decorationFormOptions: [],
      applyBizTypeOptions: [],
      applySpecialZoneOptions: [],
      levelValueOptions: [],
      picUrgentOptions: [],
      levelValue: '',
      picUrgentLevel: '',
      ruleDelayForm: {
        exceptionDesc: [{ required: true, message: '请填写延期说明', trigger: 'change' }],
        afterAdjustTime: [{ required: true, message: '请选择延期后预计提报时间', trigger: 'change' }]
      },
      pickerOptions: {
        disabledDate(time) {
          var date = new Date()
          var y = date.getFullYear()
          var m = date.getMonth() + 1
          var d = date.getDate()
          var nowTime = new Date(`${y}-${m}-${d} 00:00:00`)
          return time.getTime() < nowTime.getTime()
        }
      },
      // BEFORE_ADJUST_TIME 调整前时间
      // AFTER_ADJUST_TIME  申请延期时间
      // DELAY_DAY  延期天数

      delayForm: {
        exceptionDesc: '',
        delayDay: 0,
        afterAdjustTime: '', // 申请延期时间
        beforeAdjustTime: ''// 调整前时间
      }, // 延期提交表单
      activeDataId: '',
      centerDialogVisible: false,
      loading: false,
      delayVisible: false,
      pauseVisible: false,
      confirmVisible: false,
      showAdd: false,
      showDesign: false,
      showDesigns: false,
      // showInformation: false,
      activeTabIndex: 0,
      activeName: 'all',
      sizeForm: {},
      isAll: true,
      tableSelected: [], // 当前所选中表格行数据
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/shopDesign/getShopDesign/page`,
        hideFuncBar: true,
        pageSize: 10,
        sort: 'createTime',
        order: 'desc',
        setting: [
          {
            prop: 'constCode',
            label: '门店建设项目号',
            minWidth: 170,
            className: 'btn-green',
            isButton: true,
            clickFun: this.handleDetail
          },
          {
            prop: 'state',
            label: '设计进度',
            minWidth: 100,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_DESIGN_STATE'
            }
          },
          {
            prop: 'expectReportApplyTime',
            label: '预计提报设计申请时间',
            minWidth: 200
          },
          {
            prop: 'isApplyDelay',
            label: '设计申请是否延期',
            minWidth: 150,
            render: function(createElement, rows) {
              if (rows.isApplyDelay === 1 || rows.isApplyDelay === 0) {
                return (<div>
                  <div class={rows.isApplyDelay === 1 ? 'colorSetRed' : ''}>
                    {rows.isApplyDelay === 1 ? '是' : '否' }</div>
                </div>
                )
              }
              return ''
            }
          },
          {
            prop: 'officeName',
            label: '办事处',
            minWidth: 130
          },
          {
            prop: 'clientName',
            label: '客户',
            minWidth: 130
          },
          {
            prop: 'shopName',
            label: '门店',
            minWidth: 130
          },
          {
            prop: 'marketType',
            label: '报图类型',
            minWidth: 130,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'MARKET_TYPE'
            }
          },
          {
            prop: 'constType',
            label: '门店建设类型',
            minWidth: 130,
            render: (creat, row) => {
              if (!row.constType || !this.constTypeOptions) {
                return
              }
              let list = []
              if (typeof (row.constType) === 'string') {
                list = row.constType.split(',')
              } else {
                list = row.constType
              }
              const arr = []
              this.constTypeOptions.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'decorationForm',
            label: '装修形式',
            minWidth: 130,
            render: (creat, row) => {
              if (!row.decorationForm || !this.decorationFormOptions) {
                return
              }
              let list = []
              if (typeof (row.decorationForm) === 'string') {
                list = row.decorationForm.split(',')
              } else {
                list = row.decorationForm
              }
              const arr = []
              this.decorationFormOptions.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'decorationRange',
            label: '设计范围',
            minWidth: 130,
            render: (creat, row) => {
              if (!row.decorationRange || !this.decorationRangeOptions) {
                return
              }
              let list = []
              if (typeof (row.decorationRange) === 'string') {
                list = row.decorationRange.split(',')
              } else {
                list = row.decorationRange
              }
              const arr = []
              this.decorationRangeOptions.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }

          },
          {
            prop: 'picUrgentLevel',
            label: '图纸紧急程度',
            minWidth: 130,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PIC_URGENT_LEVEL'
            }
          },
          {
            prop: 'isKaMarket',
            label: '是否KA卖场',
            minWidth: 130,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'applyBizType',
            label: '设计申请业务类型',
            minWidth: 130,
            render: (creat, row) => {
              if (!row.applyBizType || !this.applyBizTypeOptions) {
                return
              }
              let list = []
              if (typeof (row.applyBizType) === 'string') {
                list = row.applyBizType.split(',')
              } else {
                list = row.applyBizType
              }
              const arr = []
              this.applyBizTypeOptions.forEach((item) => {
                const flag = list.some(v => v === item.dictCode)
                if (flag) {
                  arr.push(item.dictName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          {
            prop: 'applySpecialZone',
            label: '申请设计区域',
            minWidth: 130,
            render: (creat, row) => {
              if (!row.applySpecialZone || !this.applySpecialZoneOptions) {
                return
              }
              let list = []
              if (typeof (row.applySpecialZone) === 'string') {
                list = row.applySpecialZone.split(',')
              } else {
                list = row.applySpecialZone
              }
              const arr = []
              this.applySpecialZoneOptions.forEach((item) => {
                const flag = list.some(v => v === item.areaCode)
                if (flag) {
                  arr.push(item.areaName)
                }
              })
              return (<span>{ arr.toString() }</span>)
            }
          },
          // {
          //   prop: 'actureApplySampleSpace',
          //   label: '实际上样空间',
          //   minWidth: 130
          // },
          {
            prop: 'applicantName',
            label: '设计申请人',
            minWidth: 130
          },
          {
            prop: 'archiveTime',
            label: '归档时间',
            minWidth: 130
          },
          { prop: 'firstApplyDate',
            label: '首次设计申请时间',
            minWidth: 130
          }, {
            prop: 'newApplyDate',
            label: '最新设计申请时间',
            minWidth: 130
          }, {
            prop: 'passingDate',
            label: '设计申请审核通过时间',
            minWidth: 130
          }
        ]
      },
      current: {}
    }
  },
  computed: {
    otherFilters() {
      return [...this.serachFilters, ...this.typeFilters]
    },
    selectedIds() {
      return this.tableSelected.map(row => {
        return row.id
      })
    },
    exportAllConfig() {
      return [{
        code: 'export',
        name: this.isCustomize ? '定制产品报图' : !this.flag ? '门店设计基础信息' : '门店设计基础系列信息',
        dataApi: this.isCustomize ? '/slm-admin/api/v1/shopDesign/exportPicReportSeries' : !this.flag ? '/slm-admin/api/v1/shopDesign/export' : '/slm-admin/api/v1/shopDesign/exportSeries',
        selectedRows: this.tableSelected,
        paramsRaw: {},
        headers: { 'Permission-perCode': 'shopdesign' },
        filtersRaw: this.otherFilters,
        queryField: 'id'// this.isCustomize ? 'constCode' :
      }]
    }
  },
  watch: {
    type: {
      handler(v) {
        this.setOtherFilters(v)
      },
      immediate: true
    },
    serachFilters: {
      handler(v) {
        if (this.activeType !== this.type) return
        this.$nextTick(() => {
          this.$refs.cTableBox.initTableData()
        })
      }
    }
  },
  activated() {
    if (this.ready && this.refreshTableData) {
      this.refreshTableData()
    }
  },
  deactivated() {
    this.ready = true
  },
  created() {
    this.getDict()
    this.getAreaSelect()
  },
  methods: {
    setTableHeight() {
      this.$refs.cTableBox.refreshTableHeight()
    },
    async  changeLevel() {
      if (!this.singleJudge(this.tableSelected, '变更', true)) {
        return
      }
      if (this.tableSelected[0].state !== 'D' && this.tableSelected[0].state !== 'E' && this.tableSelected[0].state !== 'F') {
        this.$message.warning('进度为【设计中】，【处理中】或【已完成】时才可变更')
        return
      }
      this.levelValue = this.tableSelected[0].shopLevelCode
      this.picUrgentLevel = this.tableSelected[0].picUrgentLevel
      this.showDlg = true
    },
    handleClose() {
      this.showDlg = false
      this.levelValue = ''
      this.picUrgentLevel = ''
    },
    // 确认更改店面等级
    handleSureLevel() {
      const data = {
        shopLevelCode: this.levelValue,
        picUrgentLevel: this.picUrgentLevel,
        id: this.tableSelected[0].id
      }
      editShopLevelCode(data).then(res => {
        if (res.success) {
          this.$message.success('变更成功')
          this.showDlg = false
          this.refreshTableData()
        }
      })
    },
    /**
     *   仅门店设计范围为“门头”，且门店建设整体进度是否完成为“否”的数据可操作此按钮
         含卖场的设计申请数据不允许操作此按钮；
     */
    handleTerminal() {
      if (!this.singleJudge(this.tableSelected, '终止', true)) {
        return
      }
      if (this.tableSelected[0].decorationRange !== 'DOOR' || this.tableSelected[0].constState !== 'A') {
        this.$message.warning('当前设计数据不允许终止!')
        return
      }
      this.outerVisible = true
      this.terminationForm.id = this.tableSelected[0].id
    },
    async handleConfirmTerminal() {
      const pass = await this.$refs['refTerminalForm'].validate()
      if (!pass) return
      this.$confirm('当前操作将终止当前门头设计任务，同时终止对应的门店建设项目号，是否确认?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        termination(this.terminationForm).then(res => {
          if (res.success === 1) {
            this.$message.success('终止成功!')
            this.outerVisible = false
            this.termination = { id: '', endReason: '' }
            this.refreshTableData(true)
          }
        })
      })
    },
    // 设计申请确认
    handleConfirm() {
      if (!this.singleJudge(this.tableSelected, '确认', true)) {
        return
      }
      this.current = this.tableSelected[0]
      this.confirmVisible = true
    },
    // 设计变更，提交1，不触发BPM
    handleDesignChange() {
      if (!this.singleJudge(this.tableSelected, '变更', true)) {
        return
      }
      if (this.tableSelected[0].state === 'A' || this.tableSelected[0].isEnd === '1') {
        this.$message.warning('当前状态下不能变更')
        return
      }
      this.$router.push({ name: 'FromDesignChange', query: { id: this.tableSelected[0].id, type: '1' }})
    },
    closeDelayForm() {
      this.delayVisible = false
      this.delayForm = {
        exceptionDesc: '',
        delayDay: 0,
        afterAdjustTime: ''
      } // 延期提交表单
      this.delayLoading = false
      this.$refs.refDelayForm.resetFields()
    },
    selectionChange(v) {
      this.tableSelected = v
    },

    // 提交延期申请
    async  submitdelayForm() {
      this.delayForm.beforeAdjustTime = this.current.expectReportApplyTime
      const pass = await this.$refs['refDelayForm'].validate()
      if (!pass) return
      const upData = {
        constCode: this.current.constCode || '',
        modelId: this.current.id || '',
        exceptionHandleId: '',
        bizCode: this.current.constCode || '',
        bizName: '',
        belongModel: 'SHOP_DESIGN',
        exceptionDesc: this.delayForm.exceptionDesc,
        shopExceptionDetailDTOS: [this.delayForm]
      }
      this.delayLoading = true
      await getExceptionType('延期申请', 'SHOP_DESIGN').then(res => {
        if (res.success === 1 && res.data.records.length > 0) {
          upData.exceptionHandleId = res.data.records[0].id
        }
      })
      if (!upData.exceptionHandleId) {
        this.$message.warning('未获取到异常配置id')
        this.delayLoading = false
        return
      }
      // this.saveLoading = true
      console.log('延期', upData, this.files)
      const fileList = this.files.map(el => { return el.response.data })
      this.$set(upData, 'shopAttachmentDTOS', fileList)
      await saveException(upData).then(res => {
        if (res.success === 1) {
          this.$message.success('延期申请提交成功')
          this.refreshTableData(true)
          this.delayLoading = false
          this.closeDelayForm()
        }
      }).catch(() => {
        this.delayLoading = false
      })
      this.closeDelayForm()
    },
    extensionRequest() {
      if (!this.singleJudge(this.tableSelected, '延期申请', true)) {
        return
      }
      this.current = this.tableSelected[0]
      this.delayVisible = true
    },
    getAreaSelect() {
      getAreaList().then(res => {
        if (res.success === 1) this.applySpecialZoneOptions = res.data.records
      })
    },
    async getDict() {
      const { BIZ_TYPE, STOP_REASON_TYPE, CONST_TYPE, DECORATION_RANGE, DECORATION_FORM, SHOP_LEVEL_CODE, PIC_URGENT_LEVEL } =
       await getDictByPatchType(['BIZ_TYPE', 'STOP_REASON_TYPE', 'CONST_TYPE', 'DECORATION_RANGE', 'DECORATION_FORM', 'SHOP_LEVEL_CODE', 'PIC_URGENT_LEVEL'])
      this.doorHeadOptions = STOP_REASON_TYPE
      this.constTypeOptions = CONST_TYPE // 门店建设
      this.decorationRangeOptions = DECORATION_RANGE// 门店装修范围
      this.decorationFormOptions = DECORATION_FORM// 装修形式
      this.applyBizTypeOptions = BIZ_TYPE
      this.levelValueOptions = SHOP_LEVEL_CODE
      this.picUrgentOptions = PIC_URGENT_LEVEL
    },
    // 点击新增
    add() {
      this.$router.push({ name: 'DesignEdit' })
      // this.showAdd = true
    },
    // 点击修改
    edit() {
      if (!this.singleJudge(this.tableSelected, '编辑', true)) {
        return
      }
      this.id = this.tableSelected[0].id
      this.$router.push({ name: 'DesignEdit', query: { id: this.id }})
      // this.showDesign = true
    },
    // 暂停按钮
    pause() {
      if (!this.singleJudge(this.tableSelected, '暂停', true)) {
        return
      }
      if (this.tableSelected[0].state !== 'D' && this.tableSelected[0].state !== 'E') {
        this.$message.warning('当前状态下不能暂停')
        return
      }
      if (this.tableSelected[0].constState !== 'A') {
        this.$message.warning('建设状态正常时才能暂停')
        return
      }
      this.current = this.tableSelected[0]
      this.pauseVisible = true
    },
    // 恢复
    async  regain() {
      if (!this.singleJudge(this.tableSelected, '恢复', true)) {
        return
      }
      // 进度值为“已保存、已提交、已完成”的，不允许操作此按钮
      if (this.tableSelected[0].state === 'A' || this.tableSelected[0].state === 'B' || this.tableSelected[0].state === 'F') {
        this.$message.warning('当前状态下不能操作')
        return
      }
      if (this.tableSelected[0].isStoping === '0') {
        this.$message.warning(`设计数据：${this.tableSelected[0].constCode}下没有暂停状态的图纸`)
        return
      }
      this.current = this.tableSelected[0]
      const submitForm = {
        exceptionHandleId: '',
        bizCode: this.current.constCode || '',
        bizName: '',
        exceptionDesc: '',
        constCode: this.current.constCode || '',
        modelId: this.current.id || '',
        belongModel: 'SHOP_DESIGN',
        shopExceptionDetailDTOS: [{ exceptionDesc: '' }]
      }
      await getExceptionType('恢复').then(res => {
        if (res.success === 1 && res.data.records.length > 0) {
          submitForm.exceptionHandleId = res.data.records[0].id
        }
      })
      if (!submitForm.exceptionHandleId) {
        this.$message.warning('未获取到异常配置id')
        return
      }
      this.current = this.tableSelected[0]
      this.$prompt('请输入恢复说明', {
        confirmButtonText: '确定',
        closeOnClickModal: false,
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = ''
            submitForm.shopExceptionDetailDTOS[0].exceptionDesc = instance.inputValue || ''
            submitForm.exceptionDesc = instance.inputValue || ''
            saveException(submitForm).then(res => {
              if (res.success === 1) {
                this.$message.success('恢复申请提交成功')
                this.refreshTableData(true)
                instance.confirmButtonLoading = false
                done()
                this.$emit('success', true)
              }
            })
          } else {
            done()
          }
        }
      })
    },
    handleCustomize() {
      const params = this.tableSelected.map(v => v.constCode)
      getCustomizeFile({ constCodes: params }).then(res => {

      })
    },
    // 导出
    handleExport(data) {
      if (data === 'customized') {
        this.isCustomize = true
        // this.showCustomizeDlg = true
      } else {
        this.isCustomize = false
        this.flag = data || false
      }
      this.exportVisible = true
    },
    handleDetail(val) {
      this.$router.push({ name: 'DesignDetail', query: { id: val.id }})
    },
    // 发起变更,提交审批2，触发BPM
    handleChange() {
      if (!this.singleJudge(this.tableSelected, '变更', true)) {
        return
      }
      if (this.tableSelected[0].state === 'A' || this.tableSelected[0].state === 'B' || this.tableSelected[0].isEnd === '1') {
        this.$message.warning('当前状态下不能变更')
        return
      }
      this.$router.push({ name: 'FromDesignChange', query: { id: this.tableSelected[0].id, type: '2' }})
    },
    countDays(dateString1, dateString2) {
      if (!dateString1 || !dateString1) return 0
      const startDate = Date.parse(dateString1.slice(0, 10))
      const endDate = Date.parse(dateString2.slice(0, 10))
      if (startDate >= endDate) {
        return 0
      }
      const days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000)
      return days
    },
    changeDate(data) {
      this.delayForm.delayDay = this.countDays(this.current.expectReportApplyTime, data)
    },
    // 设置过滤条件
    setOtherFilters(v) {
      switch (v) {
        case 'all':
          this.typeFilters = []
          break
        case 'submit':
          this.typeFilters = [
            otherFiltersItem('state', 'A', '='),
            otherFiltersItem('isEnd', '0', '=')
          ]
          break
        case 'confirm':
          this.typeFilters = [
            otherFiltersItem('state', 'B', '='),
            otherFiltersItem('isEnd', '0', '=')
          ]
          break
      }
    },
    // 刷新表格
    refreshTableData(v = 'onPage') {
      this.$nextTick(() => {
        this.$refs.cTableBox.initTableData(v)
      })
    },
    // 导出成功
    handleExportSuccess() {
      this.$message.success('导出成功！')
    },
    // 导入成功
    handleImportSuccess() {
      this.$message.success('导入成功！')
    }
  }
}
</script>
